/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.component.upload.service.processor;

import com.google.common.collect.Lists;
import info.peigen.hotpot.common.service.base.processor.Processor;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import info.peigen.hotpot.component.upload.domain.UploadBatch;
import info.peigen.hotpot.component.upload.service.order.UploadBatchOrder;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Component;

/**
 * <b>(ActiveUploadBatchProcessor)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2022/11/14
 */
@Slf4j
@Component
public class ActiveUploadBatchProcessor extends AbstractUploadServiceProcessor implements Processor {
    @Override
    public Integer level() {
        return 11;
    }

    @Override
    public void execute(ProcessorServiceContext serviceContext) {
        if (serviceContext.getOrder() instanceof UploadBatchOrder) {
            active((UploadBatchOrder) serviceContext.getOrder(), serviceContext);
        }
    }

    private void active(UploadBatchOrder order, ProcessorServiceContext serviceContext) {
        UploadBatch uploadBatch = UploadBatch.builder()
                .fileNames(Lists.newArrayList(order.getFileNames()))
                .uploadedFileList(Lists.newArrayList(order.getUploadedFileList()))
                .uploadPath(order.getUploadPath())
                .build();
        serviceContext.setDomain(uploadBatch);
    }
}